package com.mbengue.corp.apr.ra.core;

import java.io.Serializable;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name = "imagearticle", schema = "apr_ra")
@NamedQueries(value = {
    @NamedQuery(name = "findImageByArticle", query = "SELECT ad FROM ImageArticle ad WHERE ad.article=:article"),
    @NamedQuery(name = "findArticlesByImage", query = "SELECT ad FROM ImageArticle ad WHERE ad.image=:image") })
public class ImageArticle implements Serializable {
  private static final long serialVersionUID = 1L;
  private ImageArticleId id;
  private Article article;
  private Image image;

  @EmbeddedId
  @AttributeOverrides({
      @AttributeOverride(name = "titreArticle", column = @Column(name = "titreArticle", nullable = false)),
      @AttributeOverride(name = "nomImage", column = @Column(name = "nomImage", nullable = false)) })
  public ImageArticleId getId() {
    return id;
  }

  public void setId(ImageArticleId aId) {
    id = aId;
  }

  @OneToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "titreArticle", nullable = false, insertable = false, updatable = false)
  public Article getArticle() {
    return article;
  }

  public void setArticle(Article aArticle) {
    article = aArticle;
  }

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "nomImage", nullable = false, insertable = false, updatable = false)
  public Image getImage() {
    return image;
  }

  public void setImage(Image aImage) {
    image = aImage;
  }

  public ImageArticle(ImageArticleId aIdIA, Article aArticle, Image aImage) {
    super();
    id = aIdIA;
    article = aArticle;
    image = aImage;
  }

  public ImageArticle() {
    // TODO Auto-generated constructor stub
  }
}
